import React,{useReducer} from 'react';

/**
 * 单纯的reducer方法
 */
function ReducerDemo() {

    const [count, dispatch] = useReducer((state,action) => {
        switch(action) {
            case 'add':
                return state+1
                case 'sub':
                    return state-1
                    default:
                        return false
        }
    }, 0)

    return (
        <div>
            <h2>现在的分数是{count}</h2>
            <button onClick={()=>dispatch('add')}>Add</button>
            <button onClick={()=>dispatch('sub')}>Decrease</button>
        </div>
    )
}

export default ReducerDemo;